package cn.itcast.bos.web.action.base;

import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;


import cn.itcast.bos.domain.base.Standard;
import cn.itcast.bos.domain.utils.BaseAction;
import cn.itcast.bos.service.base.StandardService;

@ParentPackage("json-default")
@Namespace("/")
@Actions
@Controller
@Scope("prototype")
public class StandardAction extends BaseAction<Standard> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Standard standard = new Standard();

	@Autowired
	private StandardService standardService;

	@Action(value = "standard_save", results = {
			@Result(name = "success", type = "redirect", location = "/pages/base/standard.html") })
	public String save() {

		standardService.save(standard);

		return SUCCESS;
	}
	@Action(value = "standard_findAll", results = { @Result(name = "success", type = "json") })
	public String findAll() {
		// 封装数据 Pageable中的page的索引默认是从0开始
		Pageable pageable = new PageRequest(page - 1, rows);
		Page<Standard> standard = standardService.findAll(pageable);

		pushPageDataToValueStack(standard);

		return SUCCESS;
	}

	/***
	 * 查询收派标准名字
	 */
	@Action(value = "findStandardByName", results = { @Result(name = "success", type = "json") })
	public String findStandardByName() {

		List<Standard> standardNam = standardService.findAll();

		ServletActionContext.getContext().getValueStack().push(standardNam);

		return SUCCESS;
	}

}
